<?php
/***************************************************************************
 *
 *   copyright            : (C) 2006 Erik Forbes
 *
 *   $Id: socialfilter.php 129 2011-06-08 18:25:15Z stormerider $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

$socialfilter = array(
            'TYPE'		=>      'filter',
			'NAME'		=>      'Social Networks Quicklink Filter',
			'VERSION'	=>      '1.0.0',
			'CREDIT'	=>      'StormeRider',
			'FUNC'		=>      'pluginSocialFilter',
			'HELP'		=>      'pluginSocialFilterHelp'
		);
$plugins[]	= $socialfilter;

function pluginSocialFilterHelp($help) {
	global	$socialfilter;

	$help['social1']    = array('twitter:[username]',
				            'Shows a chat-friendly link to the twitter.com account for [username]' .
				            pluginCredit($socialfilter)
				          );
	$help['social2']    = array('fb:[username]',
				            'Shows a chat-friendly link to the facebook.com account for [username]' .
				            pluginCredit($socialfilter)
				          );
	$help['social3']    = array('facebook:[username]',
				            'Shows a chat-friendly link to the facebook.com account for [username]' .
				            pluginCredit($socialfilter)
				          );

	return $help;
}

function pluginSocialFilter($msg) {
	global	$db;
	global	$dbprefix;
	
	// twitter:whatever should translate to:
	//    <a target="_blank" href="http://twitter.com/[username]">Twitter: [username]</a>
	
	if (eregi("twitter:", $msg)) {
		$msg	= eregi_replace("twitter:([[:alnum:]]+)", "<a href=\" http://twitter.com/\\1\" target=\"_blank\">Twitter: \\1</a>", $msg);
	}
	
	// fb:whatever should translate to:
	//    <a target="_blank" href="http://facebook.com/[username]">Facebook: [username]</a>
	
	if (eregi("fb:", $msg)) {
		$msg	= eregi_replace("fb:([[:alnum:]]+)", "<a href=\" http://facebook.com/\\1\" target=\"_blank\">Facebook: \\1</a>", $msg);
	}
	
	// facebook:whatever should translate to:
	//    <a target="_blank" href="http://facebook.com/[username]">Facebook: [username]</a>
	
	if (eregi("facebook:", $msg)) {
		$msg	= eregi_replace("facebook:([[:alnum:]]+)", "<a href=\" http://facebook.com/\\1\" target=\"_blank\">Facebook: \\1</a>", $msg);
	}
	
	return $msg;
}

?>
